/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.fyx.web;

import java.util.Locale;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.fyx.core.FyxCoreLocal;
import org.fyx.core.entity.FyxAtribute;
import org.fyx.mula.ejb.MulaLocal;
import org.fyx.web.context.WebPage;

/**
 *
 * @author xljan
 */
@ManagedBean
@SessionScoped
public class FyxAtributes {
    
    @EJB
    private FyxCoreLocal fyxCore;
    @EJB
    private MulaLocal mula;
    private FyxAtribute decimalSeparator;
    private FyxAtribute dateFormat;
    private FyxAtribute currency;
    private FyxAtribute isoLanguage;

    public FyxAtribute getCurrency() {
        return currency;
    }

    public FyxAtribute getDateFormat() {
        return dateFormat;
    }

    public FyxAtribute getDecimalSeparator() {
        return decimalSeparator;
    }

    public FyxAtribute getIsoLanguage() {
        return isoLanguage;
    }

    public void setIsoLanguage(FyxAtribute isoLanguage) {
        this.isoLanguage = isoLanguage;
    }
    
    
    
    @PostConstruct
    public void init(){
        decimalSeparator = fyxCore.getAtribute(FyxAtribute.DECIMAL_SEPARATOR);
        if(decimalSeparator == null){
            decimalSeparator = new FyxAtribute(FyxAtribute.DECIMAL_SEPARATOR);
            decimalSeparator.setValue(",");
        }
        dateFormat = fyxCore.getAtribute(FyxAtribute.DATE_PATTERN);
        if(dateFormat == null){
            dateFormat = new FyxAtribute(FyxAtribute.DATE_PATTERN);
            dateFormat.setValue("dd.mm.yyyy");
        }
        currency = fyxCore.getAtribute(FyxAtribute.CURRENCY);
        if(currency == null){
            currency = new FyxAtribute(FyxAtribute.CURRENCY);
            currency.setValue("Kč");
        }
        isoLanguage = fyxCore.getAtribute(FyxAtribute.ISO_LANGUAGE);
        if(isoLanguage == null){
            isoLanguage = new FyxAtribute(FyxAtribute.ISO_LANGUAGE);
            isoLanguage.setValue("cs");
        }
    }

    public void save(){
        fyxCore.setAtribute(decimalSeparator);
        fyxCore.setAtribute(dateFormat);
        fyxCore.setAtribute(currency);
        fyxCore.setAtribute(isoLanguage);
        WebPage.sendMessage(FacesMessage.SEVERITY_INFO, mula.get("Save sucefull"));
    }
    
}
